package com.lyf.config;

import com.lyf.beans.component.HelloSpringFactoryBean;
import com.lyf.beans.component.RestTemplate;
import com.lyf.beans.component.ThirdClass;
import com.lyf.beans.entity.Person;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.*;

/**
 * @AUTHOR LYF
 * @DATE 2022/5/12
 * @VERSION 1.0
 * @DESC
 */
// 指定扫描包下带注解的类
//@ComponentScan(value = "com.lyf")
// 排除所扫描的包

//@ComponentScan(value = "com.lyf",excludeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION,value = Controller.class),
//        @ComponentScan.Filter(type = FilterType.CUSTOM)
//})

//@ComponentScan(value = "com.lyf",includeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION,value = Controller.class),
//        //
//        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {TestService.class,HelloSpring.class})
//
//        //Custom 自定义
//
//},useDefaultFilters = false)


//@PropertySources(value = {@PropertySource("")})
@PropertySource(value = {"classpath:/properties/person.properties"})
@Configuration
@Import(ThirdClass.class)
public class HelloSpringConfig implements ApplicationContextAware {
    // 默认单实例---

//    @Scope("prototype")
//    @Bean
//    HelloSpring helloSpring(){
//        return new HelloSpring("test");
//    }
    private ApplicationContext context;

    @Bean
    @Conditional(value = {MyCondition.class})
    RestTemplate restTemplate(){return new RestTemplate();}

    @Bean
    HelloSpringFactoryBean helloSpringFactoryBean(){
        return new HelloSpringFactoryBean();
    }

    @Bean
    Person person(){
        return new Person();//new Person("hello",1);
    }



    public void configTest(){
        System.out.println("config...");
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //System.out.println(applicationContext.getBean(""));
        this.context = applicationContext;
    }
}
